package com.jwaoo.mobile.fcm;

import android.content.Intent;
import android.os.Bundle;

import com.dx.as.common.log.LogUtil;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.jwaoo.mobile.forchat.IFroChatMouleImpl;

/**
 * Created by jwaoo on 2017/6/21.
 */


public class MyFirebaseMessagingService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        LogUtil.d("fcm","onMessageReceived");
    }

    @Override
    public void onCreate() {
        super.onCreate();
        LogUtil.d("fcm","onCreate");
    }



    @Override
    public void handleIntent(Intent intent) {
        LogUtil.d("fcm","handleIntent");
        Bundle bundle = intent.getExtras();
        long time = Long.parseLong(bundle.getCharSequence("timestamp").toString());
        int friend = Integer.parseInt(bundle.getString("senderId"));
        String jsonStr = bundle.getCharSequence("msg").toString();
        //保存消息到聊天数据库
        LogUtil.d("jsonStr","from FCM  "+jsonStr);
        IFroChatMouleImpl.getInstance().savePushMsg(jsonStr,time,friend);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        LogUtil.d("fcm","onDestroy");
    }
}
